<template>
  <div class="newmusic-container">
    <div class="newmusic-title">
      <h1>最新音乐<span class="el-icon-arrow-right"></span></h1>
    </div>
    <div class="newmusic-list">
      <div class="music-item" v-for="item in newSongs" :key="item.id" @dblclick="playThisMusic(item)">
        <div class="music-img" @click="playThisMusic(item)">
          <img :src="item.picUrl">
          <span class="el-icon-caret-right"></span>
        </div>
        <div class="music-info">
          <p class="name">{{ item.name }}<span v-if="item.song.alias.length > 0" class="alias">({{ item.song.alias[0]
          }})</span>
          </p>
          <p class="arname">
            <el-tag v-if="item.song.fee == 1" effect="plain" size="mini" class="vip-tag">VIP</el-tag>
            <el-tag v-if="item.song.sqMusic" effect="plain" size="mini" class="sq-tag">SQ</el-tag>
            <el-tag v-if="item.song.mvid != 0" effect="plain" size="mini" class="sq-tag">MV<i
                class="el-icon-caret-right"></i>
            </el-tag>
            <i v-if="item.song.pc" class="el-icon-cloudy"></i>
            <span v-for="(artist, i) in item.song.artists" :key="artist.id"><i v-if="i == 1" class="fenge"
                @click="$router.push('/artists/' + artist.id)">/</i>{{
                    artist.name
                }}</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "@/request/request";
export default {
  data() {
    return {
      newSongs: []
    }
  },
  created() {
    this.getNewSongs()
  },
  methods: {
    async getNewSongs() {
      const { data: res } = await axios.get('/personalized/newsong?limit=16')
      if (res.code == 200) {
        this.newSongs = res.result
      }
    },
    playThisMusic(item) {
      item.song.al = { picUrl: item.picUrl }
      this.$store.dispatch('audio/getSongUrl', item.song)
    }
  }
}
</script>

<style lang="less" scoped>
.newmusic-container {
  width: 100%;
  margin-top: 20px;

  .newmusic-title {
    color: white;
    text-align: start;

    h1 {
      margin: 0;
      font-size: 20px;

      span {
        font-size: 20px;
        font-weight: 700;
        transform: translateY(1px);
      }
    }
  }

  .newmusic-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
    cursor: default;

    .music-item {
      display: flex;
      align-items: center;
      width: 250px;
      height: 60px;
      border-radius: 3px;
      padding-left: 5px;
      margin-top: 20px;
      background-color: #fff;

      .music-img {
        position: relative;
        width: 50px;
        height: 50px;
        border-radius: 3px;
        margin-right: 10px;
        overflow: hidden;

        img {
          width: 100%;
          height: 100%;
        }

        .el-icon-caret-right {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          width: 30px;
          height: 30px;
          border-radius: 50%;
          background-color: rgba(255, 255, 255, 0.9);
          color: rgb(117, 37, 197);
          font-size: 25px;
          text-align: center;
          line-height: 30px;
        }
      }

      .music-info {
        width: 70%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: space-between;
        padding: 10px 0;
        height: 100%;

        p {
          margin: 0;
          text-align: start;
        }

        .name {
          width: 100%;
          font-size: 15px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;

          .alias {
            color: rgb(123, 123, 123);
            margin-left: 3px;
          }
        }

        .arname {
          display: flex;
          align-items: center;
          width: 100%;
          font-size: 12px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          color: rgb(123, 123, 123);

          span {
            &:hover {
              color: rgb(96, 96, 96);
            }
          }

          .vip-tag {
            color: #d83b55;
            border: 1px solid #d83b55;
          }

          .sq-tag {
            color: #962ed6;
            border: 1px solid #962ed6;

          }

          .fenge {
            margin: 0 3px;
            font-size: 13px;
          }

        }
      }
    }
  }

  /deep/ .el-tag--mini {
    height: 13px;
    font-size: 12px;
    line-height: 12px;
    padding: 0 1px;
    border-radius: 2px;
    margin-right: 3px;
  }

  /deep/ .el-icon-cloudy {
    font-size: 20px;
  }
}
</style>